var app = angular.module('myApp', []);

app.controller('questionController', function($rootScope,$scope,$http,$location) {
	
    var getBasePath = globalPath.getBasePath;
	
	// var questionList = [
 //    	{
 //    		"questionId" : 1,
 //    		"questionDesc" : "aaaaaa"
 //    	},
 //    	{
 //    		"questionId" : 2,
 //    		"questionDesc" : "bbbbbb"
 //    	},
 //    	{
 //    		"questionId" : 3,
 //    		"questionDesc" : "cccccc"
 //    	},
 //    	{
 //    		"questionId" : 4,
 //    		"questionDesc" : "dddddd"
 //    	}
 //    ];
    var questionList = [];
    var getUrl = getBasePath() + 'question/back_all';
    $scope.init = function() {
        $http({
            method : 'GET',
            url : getUrl,
            params : {

            },
        }).
        success(function(response) {
            console.log("success");
            console.log(response);
            questionList = response.data;
            $scope.questionList = questionList;
        }).
        error(function(response) {
            console.log("error");
            console.log(response);
        });
    }

    $scope.init();

    $scope.questionList = questionList;

    $scope.refresh = function() {
    	$scope.searchQustionId = '';
    	$scope.init();
    }

    $scope.search = function() {
    	var findList = [];
    	var id = $scope.searchQustionId;
    	for (var i=0; i<questionList.length; i++) {
    		if (questionList[i].questionId == id) {
    			findList.push(questionList[i]);
    		}
    	}
    	$scope.questionList = findList;
    }

	$scope.questionAddUrl = getBasePath() + "admin/question/add";
	$scope.questionAddByExcel = getBasePath() + "admin/question/addByExcel";

});